<template>
  <el-container class="home-container">
    <!--    头部区域-->
    <el-header>
      <div>
        <img src="../assets/OIP.jpg" width="200px" alt="">
        <span>EDA远程实境实验管理系统 教师端</span>
      </div>
      <el-button type="danger" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体区域-->
    <el-container>
      <!--侧边栏-->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!--        折叠-->
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!--        侧边菜单-->
        <el-menu background-color="#09233c" text-color="#fff" active-text-color="#3a8ee6" unique-opened
                 :collapse="isCollapse" :collapse-transition="false" :router="true" :default-active="$route.path">
          <el-menu-item index="/course_mg">
            <i class="el-icon-s-management"></i>
            <span slot="title">课程管理</span>
          </el-menu-item>
          <el-menu-item index="/exp_mg">
            <i class="el-icon-menu"></i>
            <span slot="title">实验管理</span>
          </el-menu-item>
          <el-menu-item index="/student_mg">
            <i class="el-icon-user-solid"></i>
            <span slot="title">学生管理</span>
          </el-menu-item>
          <el-menu-item index="/push">
            <i class="el-icon-document-add"></i>
            <span slot="title">发布模板</span>
          </el-menu-item>
          <el-menu-item index="/mark">
            <i class="el-icon-document-checked"></i>
            <span slot="title">批改报告</span>
          </el-menu-item>
          <el-menu-item index="/eval">
            <i class="el-icon-view"></i>
            <span slot="title">查看成绩</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <!-- 内容主体区域-->
      <el-main>
        <!--        路由占位符-->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'Home',
  data () {
    return {
      isCollapse: false
    }
  },
  methods: {
    async logout () {
      const flag = await this.$confirm('确认要退出吗')
      if (flag) {
        // 清空redis token
        const { data: res } = await this.$http.post('/logout')
        // 清空token
        window.sessionStorage.clear()
        console.log(res)
        // 跳转登录页
        await this.$router.push('/login')
      }
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    }
  }
}
</script>

<style lang="less" scoped>
@import "../assets/css/home.less";
</style>
